
import { getToken, setToken, removeToken } from '@/utils/auth'
import { resetRouter } from '@/router'
import  {_API} from '@/api/bai'

const types = {

    SET_DATA_DETAIL: 'SET_DATA_DETAIL',
    EMPTY_DATA:'EMPTY_DATA',
    DRUGCOLLAR_DETAIL:'DRUGCOLLAR_DETAIL',
    DRUGCOLLAR_DETAIL_RETREAT:'DRUGCOLLAR_DETAIL_RETREAT',
    INFO_STORESHOW:'INFO_STORESHOW',
    OUT_STORESHOW:'OUT_STORESHOW',
    DRUGNUMSHOW:'DRUGNUMSHOW',
 
    
   
}
const state = {
        dataDetail:{},  //字典客房
        drugCollarDetail:{}, //药品领用详情
        drugCollarDetailRetreat:{}, //药品退领详情
        into_storeShow:[], //入库详情
        out_storeShow:[],//出库详情

        drugNumShow:[],//库存管理详情

}

const mutations = {
 
  [types.SET_DATA_DETAIL]:(state, name)=> {
    state.dataDetail = name
  },
  [types.DRUGCOLLAR_DETAIL]:(state, name)=> {
    state.drugCollarDetail = name
  },
  [types.DRUGCOLLAR_DETAIL_RETREAT]:(state, name)=> {
    state.drugCollarDetailRetreat = name
  },
  [types.INFO_STORESHOW]:(state, name)=> {
    state.into_storeShow = name
  },
  [types.OUT_STORESHOW]:(state, name)=> {
    state.out_storeShow = name
  },
  [types.DRUGNUMSHOW]:(state, name)=> {
    state.drugNumShow = name
  },
  
  
  set_drugCollarDetail(state,params){
    state.drugCollarDetail[params.key]=params.val;
  },
  set_drugCollarDetailRetreat(state,params){
    state.drugCollarDetailRetreat[params.key]=params.val;
  },
  set_into_storeShow(state,params){
    state.into_storeShow[params.key]=params.val;
  }
}

const actions = {


  //药库库存管理详情
  getdrug_storedDugNumShow({ commit }, d){
    return new Promise((resolve, reject) => {
      _API.getdrug_storedDugNumShow(d).then((res)=>{
         
            if (res.code === 200 && res.data) {
              commit('DRUGNUMSHOW', res.data)
          
              resolve(res)
           
          } else {
              commit('DRUGNUMSHOW', {})
              resolve()
          }
      })
    })
  },
  getdrug_purchasShow({ commit }, d){
    return new Promise((resolve, reject) => {
      _API.getdrug_purchasShow(d).then((res)=>{
         
            if (res.code === 200 && res.data) {
              commit('SET_DATA_DETAIL', res.data)
          
              resolve(res)
           
          } else {
              commit('SET_DATA_DETAIL', {})
              resolve()
          }
      })
    })
  },
  getdrug_into_storeShow({ commit }, d){
    return new Promise((resolve, reject) => {
      _API.getdrug_into_storeShow(d).then((res)=>{
         
            if (res.code === 200 && res.data) {
              commit('INFO_STORESHOW', res.data)
          
              resolve(res)
           
          } else {
              commit('INFO_STORESHOW', {})
              resolve()
          }
      })
    })
  },
  getdrug_out_storeShow({ commit }, d){
    return new Promise((resolve, reject) => {
      _API.getdrug_out_storeShow(d).then((res)=>{
         
            if (res.code === 200 && res.data) {
              commit('OUT_STORESHOW', res.data)
          
              resolve(res)
           
          } else {
              commit('OUT_STORESHOW', {})
              resolve()
          }
      })
    })
  },
  getdrug_claimShow({ commit }, d){
    return new Promise((resolve, reject) => {
      _API.getdrug_claimShow(d).then((res)=>{
         
            if (res.code === 200 && res.data) {
              commit('DRUGCOLLAR_DETAIL', res.data)
          
              resolve(res)
           
          } else {
              commit('DRUGCOLLAR_DETAIL', {})
              resolve()
          }
      })
    })
  },
  getdrug_houseExitClaimShow({ commit }, d){
    return new Promise((resolve, reject) => {
      _API.getdrug_houseExitClaimShow(d).then((res)=>{
         
            if (res.code === 200 && res.data) {
              commit('DRUGCOLLAR_DETAIL_RETREAT', res.data)
          
              resolve(res)
           
          } else {
              commit('DRUGCOLLAR_DETAIL_RETREAT', {})
              resolve()
          }
      })
    })
  },
  emptyData({ commit }){
    return new Promise((resolve, reject) => {
      
      commit('DRUGCOLLAR_DETAIL', {})
      commit('DRUGCOLLAR_DETAIL_RETREAT', {})
      commit('INFO_STORESHOW', {})
      commit('OUT_STORESHOW', {})
      
      resolve()
    })
  },
 
 

 
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

